package handler

import (
	"fmt"
	"github.com/zeromicro/go-zero/rest/httpx"
	"iot-golangzero/admin/internal/logic"
	"iot-golangzero/admin/internal/svc"
	"iot-golangzero/admin/internal/types"
	"net/http"
)

type RequestBody struct {
	Page int `json:"page"`
	Size int `json:"size"`
	Name int `json:"name"`
}

func DevicelistHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.DeviceListRequest
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		fmt.Println(">>>>>>截获参数.....", req.Page)
		fmt.Println(">>>>>>截获参数.....", req.Size)
		fmt.Println(">>>>>>截获参数.....", req.Name)
		//req.Page, _ = strconv.Atoi(r.URL.Query().Get("page"))
		//req.Size, _ = strconv.Atoi(r.URL.Query().Get("size"))
		//req.Name = r.URL.Query().Get("name")

		l := logic.NewDevicelistLogic(r.Context(), svcCtx)
		resp, err := l.Devicelist(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
